/*
 *
 * RDTSC Fuction counts ticks of in clock cycles of the CPU
 *
 *
 */
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <immintrin.h>
/*
Copy the current 64-bit value of the processor's time-stamp counter into dst.
*/
void advanced_test(const time_t iterations){
	float r = 0;
	uint64_t avg = 0;
	uint64_t min = -1, max = 0;
	for(int i = 0; i < iterations; i++){
		const uint64_t st = _rdtsc();
		r += sqrt(st);
		const uint64_t et = _rdtsc() -st;
		avg += et;
		if(et > max)
			max = et;
		if(et < min)
			min = et;
	}

	printf("sqrt() Min Cycles: %lu\n", min);
	printf("sqrt() Avg Cycles: %lu\n", avg / iterations);
	printf("sqrt() Max Cycles: %lu\n", max);
	printf("%c\n", (char)r);
}
int main(){

	advanced_test(30000000);
	return 0;
}
